package com.ml.mall.api.industry;

import com.ml.mall.bean.base.ApiRestResult;
import com.ml.mall.bean.req.industry.IndustryAddDto;
import com.ml.mall.bean.req.industry.IndustryQueryPageDto;
import com.ml.mall.bean.req.industry.IndustryUpdDto;
import com.ml.mall.consts.PermissionConst;
import com.ml.mall.entity.industry.Industry;
import com.ml.mall.service.industry.IndustryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@Api(tags = "【auth】产业信息相关接口")
@RequestMapping("/industry")
@RestController
public class IndustryController {
    @Autowired
    private IndustryService industryService;

    @PostMapping("/new")
    @ApiOperation(value = "产业信息添加")
//  @RequiresPermissions(PermissionConst.INDUSTRY_NEW)
    public ApiRestResult addIndustry(@RequestBody @Valid IndustryAddDto dto){
        int i = industryService.addIndustry(dto);
        if (i==0){
            return ApiRestResult.err();
        }
        return ApiRestResult.ok();
    }

    @PostMapping("/edit")
    @ApiOperation(value = "产业信息修改")
//  @RequiresPermissions(PermissionConst.INDUSTRY_EDIT)
    public ApiRestResult updIndustry(@RequestBody @Valid IndustryUpdDto dto){
        int i = industryService.updIndustry(dto);
        if (i==0){
            return ApiRestResult.err();
        }
        return ApiRestResult.ok();
    }

    @PostMapping("/query_page")
    @ApiOperation(value = "产业信息的分页查询")
////  @RequiresPermissions(PermissionConst.INDUSTRY_QUERY_PAGE) //放行，不启用
    public ApiRestResult queryPageIndustry(@RequestBody IndustryQueryPageDto dto){

        com.ml.mall.bean.page.Page<Industry> industryPageRes = industryService.queryPageIndustry(dto);
        if (industryPageRes ==null){
            return ApiRestResult.err();
        }
        return ApiRestResult.ok(industryPageRes);
    }

}
